package com.llc.spring.cloud.sdk.spring;

import com.llc.spring.cloud.sdk.common.annotation.EnableSpringCloudApi;
import com.llc.spring.cloud.sdk.spring.util.ScanClassUtil;

import java.util.HashSet;
import java.util.Set;

/**
 * time 2018/8/28 11:15
 *
 * @author xiaojie.zhu <br>
 */
public class DefaultApiFinder implements ApiFinder{

    @Override
    public Set<Class<?>> findApi(String[] packs) {
        Set<Class<?>> container = new HashSet<>();

        if(packs != null && packs.length > 0){
            for (String pack : packs) {
                Set<Class<?>> tmp = ScanClassUtil.findClass(pack, true);
                container.addAll(tmp);
            }
        }
        Set<Class<?>> classes = new HashSet<>();

        for (Class<?> cz : container) {
            EnableSpringCloudApi annotation = cz.getAnnotation(EnableSpringCloudApi.class);
            if(annotation != null){
                classes.add(cz);
            }
        }
        return classes;
    }
}
